package cn.wolfcode.p2p.business.service.impl;

import cn.wolfcode.p2p.business.domain.StatisticsMonthFlow;
import cn.wolfcode.p2p.business.mapper.StatisticsMonthFlowMapper;
import cn.wolfcode.p2p.business.service.IStatisticsDayFlowService;
import cn.wolfcode.p2p.business.service.IStatisticsMonthFlowService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

@Service
@Slf4j
public class StatisticsMonthFlowServiceImpl implements IStatisticsMonthFlowService {
    @Autowired
    private StatisticsMonthFlowMapper statisticsMonthFlowMapper;

    @Autowired
    private IStatisticsDayFlowService statisticsDayFlowService;

    @Override
    public void statisticsForMonth() {
        Map<String,BigDecimal> statistics =  statisticsDayFlowService.statistics();
        StatisticsMonthFlow statisticsMonthFlow = new StatisticsMonthFlow();
        statisticsMonthFlow.setDate(new Date());
        statisticsMonthFlow.setTotalIncome(statistics.get("totalIncome"));
        statisticsMonthFlow.setTotalExpenses(statistics.get("totalExpenses"));
        statisticsMonthFlowMapper.insert(statisticsMonthFlow);
        log.debug("统计每月流水");
    }
}
